﻿using System.Collections.Generic;
using CSUtils;
using G02;
using G02.PlayerData;
using TripleJump;
using UI00;
using UnityEngine;
using UnityEngine.UI;
using U3dGameUI;
using U3dUtils;

namespace HitBall.UI.SuperSetting {
    public class UI_SuperSetting : UIBase {
        public static string prefabPath;

        protected override string _GetUIPrefabPath() {
            if (prefabPath != null) {
                return prefabPath;
            }
            return "TripleJump/UI/UI_SuperSetting/UI_SuperSetting.prefab";
        }

        public static Transform parent;

        protected override Transform _GetUIParent() {
            if (parent != null) {
                return parent;
            }
            return UIBase.uiLayer3_ui;
        }

        Button languageButton;
        Button clearDataButton, closeButton;
        Slider slider00, slider01, slider02;
        Text slider00Explain, slider01Explain, slider02Explain;
        CToggle setupFpsToggle;
        float pow = 9;

        protected override void _Init() {
            //rectTransform.GetComponent<Button>().onClick.AddListener(delegate () {
            //    Close();
            //});
            clearDataButton = GetControl<Button>("view/clearDataButton");
            closeButton = GetControl<Button>("view/closeButton");

            slider00 = GetControl<Slider>("view/slider00");
            slider00Explain = GetControl<Text>("view/slider00/explain");
            slider01 = GetControl<Slider>("view/slider01");
            slider01Explain = GetControl<Text>("view/slider01/explain");
            slider02 = GetControl<Slider>("view/slider02");
            slider02Explain = GetControl<Text>("view/slider02/explain");

            setupFpsToggle = GetControl<CToggle>("view/setupFpsToggle");

            closeButton.onClick.AddListener(delegate() {
                Close();
            });
            clearDataButton.onClick.AddListener(delegate() {
                //CMusicManage.PlayMusic(CInt4.Get(-1, 17, 352, 0));

                SystemTipsUI.TipsView2("系统提示", "数据清空后，后悔两行泪,   数据是无价的,您真的要清空数据吗?", delegate(bool isConfirm) {
                    if (isConfirm) {
                        //G01Manage.GetInstance.dataManage.playerData.ClearData();
                        CPlayerPrefs.DeleteAll();
                        CDelayMain.Delay(0.3f).SetPauseEnd("").onCallback = delegate {
                            SetInitState();
                            SystemTipsUI.TipsView("系统提示", "数据已经清楚完成");
                        };
                    }
                });
            });
            int maxLenght = Cfg_PlayerProperty.arr.Length;
            slider00.minValue = slider01.minValue = slider01.minValue = 1;
            slider00.maxValue = slider01.maxValue = slider02.maxValue = maxLenght;
            slider00.onValueChanged.AddListener(delegate(float ff) {
                int ii = (int)ff;
                TripleJumpData.curr.playerJumpLevel = ii;
                slider00Explain.text = "跳高当前等级 " + ii;
            });
            slider01.onValueChanged.AddListener(delegate(float ff) {
                int ii = (int)ff;
                TripleJumpData.curr.playerJetpackLevel = ii;
                slider01Explain.text = "喷气背包当前等级 " + ii;
            });
            slider02.onValueChanged.AddListener(delegate(float ff) {
                int ii = (int)ff;
                TripleJumpData.curr.playerOfflineRevenueLevel = ii;
                slider02Explain.text = "离线收益当前等级 " + ii;
            });

            languageButton = GetControl<Button>("view/languageButton");
            languageButton.onClick.AddListener(delegate() {
                UI_LanguageSetting.GetInstance.Open();
            });
            if (Application.platform != RuntimePlatform.WindowsEditor) {
                languageButton.gameObject.SetActive(false);
            }

            setupFpsToggle.onSelectEvent += delegate(CToggle nn) {
                ShowFPS.instance.SetIsShow(nn.isSelected);
            };
        }

        int lastHintsCardFrame;

        protected override void _Open(Dictionary<string, object> paraDic) {
            SetInitState();
        }

        protected override void _Close() {
            CPayData.goldcoin += 0;
        }

        void SetInitState() {
            slider00.value = TripleJumpData.curr.playerJumpLevel;
            slider01.value = TripleJumpData.curr.playerJetpackLevel;
            slider02.value = TripleJumpData.curr.playerOfflineRevenueLevel;
        }

        static UI_SuperSetting uI_SuperSetting {
            get {
                if (_uI_SuperSetting == null || _uI_SuperSetting.m_rootRt == null) {
                    _uI_SuperSetting = new UI_SuperSetting();
                }
                return _uI_SuperSetting;
            }
        }
        static UI_SuperSetting _uI_SuperSetting;
        static int count = 0;
        static float lastClickTime;

        public static void S_Update(float ff) {
            if (S_IsClick()) {
                S_ClickEvent();
            }
        }

        public static void S_ClickEvent() {
            //Debug.LogErrorFormat("____count={0}____time={1}___差值={2}", count, Time.time, Time.time - lastClickTime);         
            if (Time.time - lastClickTime < 0.39f) {
                S_Count();
            } else {
                count = 0;
                lastClickTime = Time.time;
                //Debug.LogErrorFormat("____count={0}____time={1}___差值={2}_______失败_______", count, Time.time, Time.time - lastClickTime);
                //UI02.UI_SystemHints.GetInstance.o_HintsCard.S_ShowMessage(Input.mousePosition, "不要做无用的点击");
            }
        }

        static bool S_IsClick() {
            if (TJTools.IsEditor()) {
                if (Input.GetMouseButtonDown(0)) {
                    return true;
                }
            } else {
                if (Input.touchCount > 0) {
                    if (Input.GetTouch(0).phase == TouchPhase.Began) {
                        return true;
                    }
                }
            }
            return false;
        }

        static void S_Count() {
            lastClickTime = Time.time;
            count++;
            if (count > 9) {
                count = 0;
                uI_SuperSetting.Open(null);
            }
        }
    }
}
